<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Article;
use app\common\model\Faq;

/**
 * 首页接口.
 */
class Index extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    /**
     * 首页.
     */
    public function index()
    {
        $this->success('请求成功');
    }

    /**
     * 常见问题列表
     */
    public function faq()
    {
        $type=request()->param('type')?:'user_miniapp';
        $page=request()->param('page')?:1;

        if($type=='user_miniapp'){
            $where=['type'=>0];
        }
        elseif($type=='worker_app'){
            $where=['type'=>1];
        }
        else{
            $this->error('用户端类型错误');
        }

        $faqs=Faq::where($where)
            ->page($page,10)
            ->order('weigh desc')
            ->field('id,title')
            ->select()?:[];

        $this->success('请求成功',$faqs);
    }

    /**
     * 常见问题列表
     */
    public function faqInfo()
    {
        $id=request()->param('id');

        if(!$id){
            $this->error('缺少问题id');
        }

        $faq=Faq::get($id);

        if(!$faq){
            $this->error('未找到问题信息');
        }

        $this->success('请求成功',$faq);
    }

    /**
     * 文章信息
     */
    public function article()
    {
        $code=request()->param('code','');
        $type=request()->param('type')?:0;

        $article=Article::get(['code'=>$code,'type'=>$type]);

        if(!$article){
            $this->error('未找到对应信息');
        }

        $this->success('请求成功',$article);
    }


    /**
     *  获取配置信息
     */
    public function info()
    {
        $code=request()->param('code','');

        if(!in_array($code,['user_top_img','driver_applink'])){
            $this->error('此数据未开放获取');
        }

        $info=config('site.'.$code);

        $this->success('请求成功',$info);
    }
}
